package cn.yuanqiao.archive.Identify.service.impl;
/**
 * @author 赵常飞
 * @date 2023/9/19 11:08
 */

import cn.yuanqiao.archive.Identify.domain.*;
import cn.yuanqiao.archive.Identify.mapper.DestructionMapper;
import cn.yuanqiao.archive.Identify.mapper.IsOpenIdentifyMapper;
import cn.yuanqiao.archive.Identify.service.IDestructionService;
import cn.yuanqiao.archive.Identify.service.IDisposeService;
import cn.yuanqiao.archive.appManager.domain.*;
import cn.yuanqiao.archive.appManager.mapper.TenantCategoryMapper;
import cn.yuanqiao.archive.appManager.service.ITenantCateMdataListService;
import cn.yuanqiao.archive.appManager.service.ITenantSysConfigService;
import cn.yuanqiao.archive.appManager.service.ITenantSysDictTypeService;
import cn.yuanqiao.archive.appManager.service.impl.TenantMijiComparisonTableServiceImpl;
import cn.yuanqiao.archive.chengguojieshou.mapper.YqdaarticulatedMapper;
import cn.yuanqiao.archive.wenjianzhengli.mapper.TenantYqdaFolderMapper;
import cn.yuanqiao.archive.wenjianzhengli.service.impl.WenjianzhengliServiceImpl;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.enums.BusinessBehavior;
import cn.yuanqiao.common.util.BusinessBehaviorUtil;
import cn.yuanqiao.common.utils.SecurityUtils;
import cn.yuanqiao.common.core.domain.model.LoginUser;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;

import static cn.yuanqiao.common.utils.PageUtils.startPage;

/**
 *
 *@AUTHOR:赵常飞
 *@date 2023/9/19 11:08
 */
@Service
public class DestructionServiceImpl implements IDestructionService {
    @Autowired
    private ITenantCateMdataListService tenantMdataListService;
    @Autowired
    private WenjianzhengliServiceImpl wenjianzhengliService;
    @Autowired
    private TenantCategoryMapper tenantCategoryMapper;
    @Autowired
    private ITenantCateMdataListService cateMdataListService;
    @Autowired
    private DestructionMapper destructionMapper;
    @Autowired
    private IsOpenIdentifyMapper isOpenIdentifyMapper;
    @Autowired
    private ITenantSysConfigService sysConfigService;
    @Autowired
    private TenantYqdaFolderMapper yqdaFolderMapper;
    @Autowired
    private IDisposeService disposeService;
    @Autowired
    private IsOpenIdentifyServiceImpl isOpenIdentifyserviceimpl;
    @Autowired
    private YqdaarticulatedMapper yqdaarticulatedMapper;
    @Value("${FBswitch}")
    private Boolean FBswitch;
    @Autowired
    private ITenantSysDictTypeService dictTypeService;
    @Autowired
    private TenantMijiComparisonTableServiceImpl mijiComparisonTableService;

    @Override
    public List<Map<String, Object>> getlistfromcz(JSONObject json) {
        Long categoryId = json.getLong("categoryId");//门类id
        Long menuId = json.getLong("menuId");//菜单id
        String subTableName = json.getString("subTableName");//层级节点的表名
        //Long fondsId=json.getLong("fondsId");//全宗id
        Long renwuid = json.getLong("renwuid");
        String fields = "ID," + json.getString("fields");//需要查询的字段
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        int type = -1;
        /**处理查询条件*/
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }

        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }

        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        /**处理表名*/
        TenantCategory category = new TenantCategory();
        String tablename = "";
        if (null != subTableName && !"".equals(subTableName)) {//有层级信息
            tablename = subTableName;
            String tablenametype = subTableName.substring(subTableName.length() - 3, subTableName.length() - 2);
            if ("F".equalsIgnoreCase(tablenametype)) {//档案层
                type = 0;
            } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
                type = 1;
            } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
                type = 1;
            } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
                type = 2;
            }
        } else {
            TenantCategory tenantCategory = tenantCategoryMapper.selectTenantCategoryByID(categoryId, category.getTableName());
            if (tenantCategory.getType() == 0) {//件
                tablename = tenantCategory.getFileTableName();
            } else if (tenantCategory.getType() == 1) {//卷
                tablename = tenantCategory.getFolderTableName();
            } else if (tenantCategory.getType() == 2) {//电子文件
                tablename = tenantCategory.getEfileTableName();
            } else if (tenantCategory.getType() == 3) {//项目
                tablename = tenantCategory.getFolderTableName();
            }
            type = tenantCategory.getType();
            if (3 == type) {
                type = 1;
            }
        }
        String tiaojian = sb.toString();
        /**处理拼接条件时的sql*/
        if (tiaojian.endsWith("and ")) {
            tiaojian = tiaojian.substring(0, tiaojian.length() - 4);
        } else if (tiaojian.endsWith("and")) {
            tiaojian = tiaojian.substring(0, tiaojian.length() - 3);
        }
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by had desc," + orderstr;
        } else {
            String applyorderstr = tenantMdataListService.getorder(categoryId, menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            } else {
                orderstr = " ";
            }
        }
        startPage();
        /** 拼接条件(bgqx到期/未鉴定过/已在流程中) */
        String bgqxgqsql = "select da_id from " + new TenantDispose().getTableName() + " where cztype='xiaohui'";
        //不在流程中
        TenantYqxhjdJobDa yqxhjdJobDa = new TenantYqxhjdJobDa();
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        String lczsql = " select daid from " + yqxhjdJobDa.getTableName() + " where renwuid in(select id from " + yqxhjdJob.getTableName() + " where is_del=0 and jiandingstate!=9 and jiandingstate!=8)";//未撤销且鉴定未完成
        /**查询列表并返回*/
        return isOpenIdentifyMapper.getlistfromcz(fields, tablename, bgqxgqsql, lczsql, tiaojian, orderstr);
    }

    @Override
    public List<Map<String, Object>> xhjdjoblist(JSONObject json) {
        String title = json.getString("title");
        if (null != title) {
            title = title.replace(" ", "");
        }
        String starttime = json.getString("starttime");
        String endtime = json.getString("endtime");
        Integer state = json.getInteger("state");
        String qzh = json.getString("qzh");
        String order = json.getString("order");
        if (null == order || "".equals(order)) {
            order = " order by jiandingstartdate desc";
        } else {
            order = " order by " + order;
        }
        return isOpenIdentifyMapper.kfjdjoblist(title, starttime, endtime, state, qzh, new TenantYqxhjdJob().getTableName(), order);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addjob(String jiandingrenwuname, String renwuno, String qzh, String qzhcode, Long jiandingleader, String chushenpeople, String fushenpeople, Long shendingpeople, String jiandingstartdate, Long categoryId, MultipartFile file, String remark,String mj) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob xhjdJob = new TenantYqxhjdJob();
        long id = SnowflakeIdGenerator.generateId();
        xhjdJob.setId(id);
        xhjdJob.setJiandingrenwuname(jiandingrenwuname);
        xhjdJob.setRenwuno(renwuno);
        xhjdJob.setQzh(qzh);
        xhjdJob.setJiandingstate(1);
        xhjdJob.setJiandingleader(jiandingleader);
        xhjdJob.setChushenpeople(chushenpeople);
        xhjdJob.setFushenpeople(fushenpeople);
        xhjdJob.setShendingpeople(shendingpeople);
        xhjdJob.setJiandingstartdate(jiandingstartdate);
        xhjdJob.setRemark(remark);
        xhjdJob.setIsDel(0);
        xhjdJob.setQzhcode(qzhcode);
        xhjdJob.setCreator(user.getUserId());
        xhjdJob.setCreateTime(DateUtils.getNowDate());
        TenantCategory category = new TenantCategory();
        TenantCategory category1 = tenantCategoryMapper.selectTenantCategoryByID(categoryId, category.getTableName());
        if (category1.getType() == 0) {
            xhjdJob.setSubTableName(category1.getFileTableName());
        } else if (category1.getType() == 1) {
            xhjdJob.setSubTableName(category1.getFolderTableName());
        } else if (category1.getType() == 3) {
            xhjdJob.setSubTableName(category1.getItemTableName());
        }
        if (file == null) {

        } else {
            TenantYqJdFile yqJdFile = new TenantYqJdFile();
            long fileid = SnowflakeIdGenerator.generateId();
            yqJdFile.setId(fileid);
            yqJdFile.setFileName(file.getResource()
                    .getFilename());
            yqJdFile.setFileSize(file.getSize());
            yqJdFile.setRenwuid(xhjdJob.getId());
            yqJdFile.setType("DESTRUCTION");
            yqJdFile.setMj(mj);
            long l = System.currentTimeMillis();
            yqJdFile.setRealFileName(l + yqJdFile.getFileName().substring(yqJdFile.getFileName().lastIndexOf("."), yqJdFile.getFileName().length()));
            String uplodPath = sysConfigService.selectConfigByKey("YQ_MNT");
            if (StringUtils.isEmpty(uplodPath)) {
                throw new ServiceException("系统参数错误YQ_MNT未找到配置！");
            }
            yqJdFile.setPath(uplodPath + File.separator + "JDFILE" + File.separator + id + File.separator);
            try {
                String absPath = yqJdFile.getPath() + File.separator + yqJdFile.getRealFileName();
                File desc = new File(absPath);
                if (!desc.exists()) {
                    if (!desc.getParentFile().exists()) {
                        desc.getParentFile().mkdirs();
                    }
                }
                file.transferTo(Paths.get(absPath));
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }

            isOpenIdentifyMapper.addfile(yqJdFile);
        }
        List<TenantSysDictData> jdzt = dictTypeService.selectDictDataByType("JDZT");
        for (int j = 0; j < jdzt.size(); j++) {
            TenantYqxhjdTask task = new TenantYqxhjdTask();
            task.setRenwuid(xhjdJob.getId());
            task.setStatus(Integer.parseInt(jdzt.get(j).getDictValue()));
            if (j == 0) {
                task.setCaozuoren(String.valueOf(user.getUserId()));
                task.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                //task.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
            }
            destructionMapper.addtask(task);
        }
        return destructionMapper.addjob(xhjdJob);
    }

    @Override
    public JSONObject getjobinfo(Long id) {
        JSONObject returnjson = new JSONObject();
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        Map<String, Object> jobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        String searchtable = (String) jobinfo.get("SUB_TABLE_NAME");
        String tablenametype = searchtable.substring(searchtable.length() - 3, searchtable.length() - 2);
        String subname = "";
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
        }
        Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), (String) jobinfo.get("SUB_TABLE_NAME"), subname);
        jobinfo.put("categoryId", cateinfo.get("ID"));
        returnjson.put("jobinfo", jobinfo);

        TenantYqJdFile yqJdFile = new TenantYqJdFile();
        yqJdFile.setRenwuid(id);
        String mjWhere = "";
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            mjWhere += " and MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') ";
        }
        returnjson.put("fileinfo", isOpenIdentifyMapper.getfileinfo(yqJdFile,mjWhere));
        return returnjson;
    }

    @Override
    public TenantYqJdFile upload(Long renwuid,String mj, MultipartFile file) {
        TenantYqJdFile yqJdFile = new TenantYqJdFile();
        long fileid = SnowflakeIdGenerator.generateId();
        yqJdFile.setId(fileid);
        yqJdFile.setFileName(file.getResource()
                .getFilename());
        yqJdFile.setFileSize(file.getSize());
        yqJdFile.setRenwuid(renwuid);
        yqJdFile.setType("DESTRUCTION");
        yqJdFile.setMj(mj);
        long l = System.currentTimeMillis();
        yqJdFile.setRealFileName(l + yqJdFile.getFileName().substring(yqJdFile.getFileName().lastIndexOf("."), yqJdFile.getFileName().length()));
        String uplodPath = sysConfigService.selectConfigByKey("YQ_MNT");
        if (StringUtils.isEmpty(uplodPath)) {
            throw new ServiceException("系统参数错误YQ_MNT未找到配置！");
        }
        yqJdFile.setPath(uplodPath + File.separator + "JDFILE" + File.separator + renwuid + File.separator);
        try {
            String absPath = yqJdFile.getPath() + File.separator + yqJdFile.getRealFileName();
            File desc = new File(absPath);
            if (!desc.exists()) {
                if (!desc.getParentFile().exists()) {
                    desc.getParentFile().mkdirs();
                }
            }
            file.transferTo(Paths.get(absPath));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        isOpenIdentifyMapper.addfile(yqJdFile);
        return yqJdFile;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updatejobinfo(TenantYqxhjdJob yqxhjdJob) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        yqxhjdJob.setUpdatedBy(user.getUserId());
        yqxhjdJob.setUpdateTime(DateUtils.getNowDate());
        TenantYqxhjdTask task = new TenantYqxhjdTask();
        task.setStatus(1);
        task.setRenwuid(yqxhjdJob.getId());
        task.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        yqxhjdJob.setJiandingstate(1);
        TenantCategory category = tenantCategoryMapper.selectTenantCategoryByID(yqxhjdJob.getCategoryId(), new TenantCategory().getTableName());
        if (category.getType() == 0) {
            yqxhjdJob.setSubTableName(category.getFileTableName());
        } else if (category.getType() == 3) {
            yqxhjdJob.setSubTableName(category.getItemTableName());
        } else {
            yqxhjdJob.setSubTableName(category.getFolderTableName());
        }
        //获取当前任务的门类
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        //如果更换门类,判断是否已经调档,已调档不允许修改
        if(!yqxhjdJob.getSubTableName().equals(getjobinfo.get("SUB_TABLE_NAME"))){
            int i=isOpenIdentifyMapper.getdanum(new TenantYqxhjdJobDa().getTableName(),yqxhjdJob.getId());
            if(i>0){
                throw new ServiceException("已经调档,无法修改门类!");
            }
        }
        destructionMapper.updatetask(task);
        return destructionMapper.updatejobinfo(yqxhjdJob);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addarchive(JSONObject json) {
        List ids = json.getJSONArray("ids");
        Long categoryId = json.getLong("categoryId");
        Long renwuid = json.getLong("renwuid");
        TenantCategory category = tenantCategoryMapper.selectTenantCategoryByID(categoryId, new TenantCategory().getTableName());
        //查询此条数据是否已经存在于此任务中,存在时直接跳过
        List<String> jobdaids = tenantCategoryMapper.getdaidsbyrenwuid(renwuid, new TenantYqxhjdJobDa().getTableName());
        if (category.getType() == 0) {//件
            for (int i = 0; i < ids.size(); i++) {
                if (jobdaids.contains(String.valueOf(ids.get(i)))) {
                    continue;
                }
                TenantYqxhjdJobDa yqxhjdJobDa = new TenantYqxhjdJobDa();
                yqxhjdJobDa.setRenwuid(renwuid);
                yqxhjdJobDa.setDaid(Long.parseLong(String.valueOf(ids.get(i))));
                yqxhjdJobDa.setType("f");
                destructionMapper.insertda(yqxhjdJobDa);
            }
        } else if (category.getType() == 1) {//卷
            for (int i = 0; i < ids.size(); i++) {
                if (jobdaids.contains(String.valueOf(ids.get(i)))) {
                    continue;
                }
                //添加卷层
                TenantYqxhjdJobDa yqxhjdJobDa = new TenantYqxhjdJobDa();
                yqxhjdJobDa.setRenwuid(renwuid);
                yqxhjdJobDa.setDaid(Long.parseLong(String.valueOf(ids.get(i))));
                yqxhjdJobDa.setType("v");
                destructionMapper.insertda(yqxhjdJobDa);
                TenantYqdaFolder yqdaFolder = new TenantYqdaFolder();
                List<String> daids = yqdaFolderMapper.selectFileIdByFolderId1(String.valueOf(ids.get(i)), yqdaFolder.getTableName(), new TenantYqda().getTableName());
                for (int j = 0; j < daids.size(); j++) {
                    TenantYqxhjdFolderDa yqxhjdFolderDa = new TenantYqxhjdFolderDa();
                    yqxhjdFolderDa.setRenwuid(renwuid);
                    yqxhjdFolderDa.setDaid(Long.parseLong(String.valueOf(daids.get(j))));
                    yqxhjdFolderDa.setType("v_f");
                    yqxhjdFolderDa.setVid(Long.parseLong(String.valueOf(ids.get(i))));
                    destructionMapper.insertfolderda(yqxhjdFolderDa);
                }
            }
        } else if (category.getType() == 3) {//项目
            for (int i = 0; i < ids.size(); i++) {
                if (jobdaids.contains(String.valueOf(ids.get(i)))) {
                    continue;
                }
                //添加项目
                TenantYqxhjdJobDa yqxhjdJobDa = new TenantYqxhjdJobDa();
                yqxhjdJobDa.setRenwuid(renwuid);
                yqxhjdJobDa.setDaid(Long.parseLong(String.valueOf(ids.get(i))));
                yqxhjdJobDa.setType("v");
                destructionMapper.insertda(yqxhjdJobDa);
                TenantYqdaFolder yqdaFolder = new TenantYqdaFolder();
                List<String> daids = yqdaFolderMapper.selectFileIdByFolderId1(String.valueOf(ids.get(i)), yqdaFolder.getTableName(), new TenantYqda().getTableName());
                for (int j = 0; j < daids.size(); j++) {
                    TenantYqxhjdFolderDa yqxhjdFolderDa = new TenantYqxhjdFolderDa();
                    yqxhjdFolderDa.setRenwuid(renwuid);
                    yqxhjdFolderDa.setDaid(Long.parseLong(String.valueOf(daids.get(j))));
                    yqxhjdFolderDa.setType("v_f");
                    yqxhjdFolderDa.setVid(Long.parseLong(String.valueOf(ids.get(i))));
                    destructionMapper.insertfolderda(yqxhjdFolderDa);
                }
            }
        }
        disposeService.deletedata(ids, "xiaohui");
        return 1;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String deletejob(Long id) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        //判断是否有删除权限
        if (!user.getUserId().equals(getjobinfo.get("CREATOR"))) {
            return "只有此条任务的创建人才能删除!";
        }
        //判断状态
        if (!"1".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            return "任务已开始,无法删除!";
        }
        TenantYqxhjdJob yqxhjdJob1 = new TenantYqxhjdJob();
        yqxhjdJob1.setId(id);
        yqxhjdJob1.setIsDel(1);
        //修改任务记录的is_del=1
        destructionMapper.updatejobinfo(yqxhjdJob1);
        return "删除成功";
    }

    @Override
    public String chexiaojob(Long id) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        //判断是否有删除权限
        if (!user.getUserId().equals(getjobinfo.get("CREATOR"))) {
            return "只有此条任务的创建人才能撤销!";
        }
        //判断状态
        if (null!=getjobinfo.get("JIANDINGENDDATE")) {
            return "鉴定结果已经生效,无法撤销!";
        }
        if ("9".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            return "此任务已经撤销,无需重复操作!";
        }
        TenantYqxhjdJob yqxhjdJob1 = new TenantYqxhjdJob();
        yqxhjdJob1.setId(id);
        yqxhjdJob1.setJiandingstate(9);
        //修改任务记录的is_del=1
        destructionMapper.updatejobinfo(yqxhjdJob1);
        return "操作成功！";
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int completedd(Long id) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        //判断任务中是否有档案
        List<TenantYqxhjdJobDa> tenantYqxhjdJobDas = destructionMapper.getyqKfjdJobDabyrenwuid(id, new TenantYqxhjdJobDa().getTableName());
        if (tenantYqxhjdJobDas.size() == 0) {
            throw new RuntimeException("任务中没有需要鉴定的档案,请先添加档案到任务单中!");
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        yqxhjdJob.setJiandingstate(2);
        TenantYqxhjdTask task = new TenantYqxhjdTask();
        task.setRenwuid(id);
        task.setStatus(2);
        task.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        if (!String.valueOf(user.getUserId()).equals(String.valueOf(getjobinfo.get("CREATOR")))) {
            throw new RuntimeException("只有创建人才可以调档完成!");
        }
        task.setCaozuoren(String.valueOf(user.getUserId()));
        destructionMapper.updatetask(task);
        TenantYqxhjdTask task1 = new TenantYqxhjdTask();
        task1.setRenwuid(id);
        task1.setStatus(1);
        task1.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        destructionMapper.updatetask(task1);
        return destructionMapper.updatejobinfo(yqxhjdJob);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deletearchive(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        List ids = json.getJSONArray("ids");
        List<TenantYqxhjdJobDa> yqxhjdJobDa = destructionMapper.getyqKfjdJobDabyrenwuid(renwuid, new TenantYqxhjdJobDa().getTableName());
        if (yqxhjdJobDa != null && yqxhjdJobDa.size() > 0) {
            TenantYqxhjdJobDa yqxhjdJobDa1 = new TenantYqxhjdJobDa();
            if ("f".equals(yqxhjdJobDa.get(0).getType())) {
                isOpenIdentifyMapper.deletejobDa(renwuid, ids, yqxhjdJobDa1.getTableName());
            } else if ("v".equals(yqxhjdJobDa.get(0).getType())) {
                isOpenIdentifyMapper.deletefolderda(renwuid, ids, new TenantYqxhjdFolderDa().getTableName());
                isOpenIdentifyMapper.deletejobDa(renwuid, ids, yqxhjdJobDa1.getTableName());
            }
        }
        return 1;
    }

    @Override
    public List<Map<String, Object>> getdatalistbyrenwuid(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String fields = "a.ID,a." + json.getString("fields").replace(",", ",a.");//需要查询的字段
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        int type = -1;
        /**处理查询条件*/
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" a.MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        String tiaojian = sb.toString();
        String chushenstate = json.getString("chushenstate");
        String fushenstate = json.getString("fushenstate");
        if (tiaojian.endsWith("and") || tiaojian.endsWith("and ")) {
            tiaojian += " 1=1 ";
        }
        if (null != chushenstate) {
            tiaojian += " and b.CHUSHEN_STATE =" + chushenstate + " ";
        }
        if (null != fushenstate) {
            tiaojian += " and b.FUSHEN_STATE =" + fushenstate + " ";
        }
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);

        String searchtable = (String) getjobinfo.get("SUB_TABLE_NAME");
        String tablenametype = searchtable.substring(searchtable.length() - 3, searchtable.length() - 2);
        String subname = "";
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            type = 0;
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            type = 1;
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            type = 3;
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
            type = 2;
        }
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), searchtable, subname);
        if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            searchtable = (String) getcateinfo.get("FOLDER_TABLE_NAME");
        }
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(getcateinfo.get("ID"))), menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        startPage();
        return isOpenIdentifyMapper.getdatalistbyrenwuid(renwuid, searchtable, fields, tiaojian, new TenantYqxhjdJobDa().getTableName(), orderstr);
    }

    @Override
    public List<Map<String, Integer>> getcsfsallnumbyrenwuid(Long id) {
        return isOpenIdentifyMapper.getcsfsallnumbyrenwuid(id, new TenantYqxhjdJobDa().getTableName());
    }

    @Override
    public boolean hasfenpeipro(Long id) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        if (String.valueOf(user.getUserId()).equals(String.valueOf(getjobinfo.get("JIANDINGLEADER")))) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean hasupdatepro(Long id) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        if (user.getUserId().equals(getjobinfo.get("CREATOR"))) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public Map<String, Object> getinfonumperson(Long id) {
        return isOpenIdentifyMapper.getinfonumperson(id, new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName());
    }

    @Override
    public List<Map<String, Object>> cspjfplist(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        Long userid = json.getLong("userid");
        Long menuId = json.getLong("menuId");
        String type = json.getString("type");//初审复审走一个接口
        String fields = "b." + json.getString("fields").replace(",", ",b.");//需要查询的字段
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        /**处理查询条件*/
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        String tiaojian = sb.toString();
        if (tiaojian.endsWith("and") || tiaojian.endsWith("and ")) {
            tiaojian += " 1=1 ";
        }
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        List<String> users = new ArrayList();
        if ("chushen".equals(type)) {//初审
            users = Arrays.asList(getjobinfo.get("CHUSHENPEOPLE").toString().split(","));
        } else {//复审
            users = Arrays.asList(getjobinfo.get("FUSHENPEOPLE").toString().split(","));
        }
        if (null == userid || users.size() == 0) {//尚未选定初审人员
            throw new RuntimeException("未选定" + (type.equals("chushen") ? "初审" : "复审") + "组人员!");
        }
        int index = -1;//当前人在用户组中的位置,用于按排序取档案
        for (int i = 0; i < users.size(); i++) {
            if (String.valueOf(userid).equals(users.get(i))) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            throw new RuntimeException("人员信息不符,请联系管理员查看!");
        }
        String searchtable = (String) getjobinfo.get("SUB_TABLE_NAME");
        String tablenametype = searchtable.substring(searchtable.length() - 3, searchtable.length() - 2);
        String subname = "";
        int ordertype = -1;
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            ordertype = 0;
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            ordertype = 1;
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            ordertype = 1;
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
            ordertype = 2;
        }
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), String.valueOf(getjobinfo.get("SUB_TABLE_NAME")), subname);
        if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            getjobinfo.put("SUB_TABLE_NAME", getcateinfo.get("FOLDER_TABLE_NAME"));
        }
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(getcateinfo.get("ID"))), menuId, ordertype);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        startPage();
        return isOpenIdentifyMapper.cspjfplist(renwuid, index, users.size(), String.valueOf(getjobinfo.get("SUB_TABLE_NAME")), new TenantYqxhjdJobDa().getTableName(), tiaojian, fields, orderstr);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int pingjunfenpeirenwu(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        if ("chushen".equals(type)) {
            if ("1".equals(getjobinfo.get("JIANDINGSTATE"))) {
                throw new RuntimeException("请先调档完成!");
            }
            if (!"2".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
                throw new RuntimeException("任务已经分发,无法调整!");
            }
        } else {
            if (4 < Integer.parseInt(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
                throw new RuntimeException("复审任务已经开始,无法分配!");
            }
        }

        List<String> users = new ArrayList();
        if ("chushen".equals(type)) {//初审
            users = Arrays.asList(getjobinfo.get("CHUSHENPEOPLE").toString().split(","));
        } else {//复审
            users = Arrays.asList(getjobinfo.get("FUSHENPEOPLE").toString().split(","));
        }
        if (users.size() == 0) {//尚未选定初审人员
            throw new RuntimeException("未选定" + (type.equals("chushen") ? "初审" : "复审") + "组人员!");
        }
        String statefield = "chushen".equals(type) ? "CHUSHEN_STATE" : "FUSHEN_STATE";
        String personfield = "chushen".equals(type) ? "CHUSHEN_PERSON" : "FUSHEN_PERSON";
        for (int i = 0; i < users.size(); i++) {
            isOpenIdentifyMapper.pingjunfenpeirenwu(new TenantYqxhjdJobDa().getTableName(), statefield, personfield, users.get(i), renwuid, i, users.size());
        }
        if(!"chushen".equals(type)) {
            TenantYqxhjdTask task = new TenantYqxhjdTask();
            task.setStatus(2);
            task.setRenwuid(renwuid);
            task.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
            destructionMapper.updatetask(task);
        }
        //分配了复审任务后,可能任务状态是4待复审,此时修改为5
        if ("fushen".equals(type) && "4".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
            yqxhjdJob.setId(renwuid);
            yqxhjdJob.setJiandingstate(5);
            destructionMapper.updatejobinfo(yqxhjdJob);
            TenantYqxhjdTask task1 = new TenantYqxhjdTask();
            task1.setStatus(4);
            task1.setRenwuid(renwuid);
            task1.setCaozuoren(String.valueOf(user.getUserId()));
            task1.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
            destructionMapper.updatetask(task1);
            TenantYqxhjdTask task2 = new TenantYqxhjdTask();
            task2.setStatus(5);
            task2.setRenwuid(renwuid);
            //task2.setCaozuoren(String.valueOf(user.getUserId()));
            task2.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
            destructionMapper.updatetask(task2);
        }

        return 1;
    }

    @Override
    public int markfp(JSONObject json) {
        List ids = json.getJSONArray("ids");
        int checked = json.getBoolean("checked") == true ? 1 : 0;
        Long renwuid = json.getLong("renwuid");
        String type = json.getString("type");
        String markfield = "";
        if ("chushen".equals(type)) {
            markfield = "CHUSHENMARK";
        } else if ("fushen".equals(type)) {
            markfield = "FUSHENMARK";
        }
        isOpenIdentifyMapper.markfp(new TenantYqxhjdJobDa().getTableName(), renwuid, ids, markfield, checked);
        return 1;
    }

    @Override
    public List<Map<String, Object>> sdfplist(JSONObject json) {
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");
        String fields = "b.id,b." + json.getString("fields").replace(",", ",b.");//需要查询的字段
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        /**处理查询条件*/
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        String tiaojian = sb.toString();
        if (tiaojian.endsWith("and") || tiaojian.endsWith("and ")) {
            tiaojian += " 1=1 ";
        }
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        String searchtable = (String) getjobinfo.get("SUB_TABLE_NAME");
        String tablenametype = searchtable.substring(searchtable.length() - 3, searchtable.length() - 2);
        String subname = "";
        int ordertype = -1;
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            ordertype = 0;
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            ordertype = 1;
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            ordertype = 1;
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
            ordertype = 2;
        }
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), String.valueOf(getjobinfo.get("SUB_TABLE_NAME")), subname);
        if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            getjobinfo.put("SUB_TABLE_NAME", getcateinfo.get("FOLDER_TABLE_NAME"));
        }
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(getcateinfo.get("ID"))), menuId, ordertype);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        startPage();
        return isOpenIdentifyMapper.sdfplist(new TenantYqxhjdJobDa().getTableName(), renwuid, "chushen".equals(type) ? "CHUSHEN_PERSON" : "FUSHEN_PERSON", String.valueOf(getjobinfo.get("SUB_TABLE_NAME")), fields, tiaojian, orderstr);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int commitsdfp(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        List ids = json.getJSONArray("daids");
        Long renwuid = json.getLong("renwuid");
        String type = json.getString("type");
        Long userid = json.getLong("userid");
        String statefield = "chushen".equals(type) ? "CHUSHEN_STATE" : "FUSHEN_STATE";
        String personfield = "chushen".equals(type) ? "CHUSHEN_PERSON" : "FUSHEN_PERSON";
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        isOpenIdentifyMapper.commitsdfp(new TenantYqxhjdJobDa().getTableName(), renwuid, userid, statefield, personfield, ids);
        //分配了复审任务后,可能任务状态是4待复审,此时修改为5
        if ("fushen".equals(type) && "4".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            int nofpcs = isOpenIdentifyMapper.getnofpcsnum(new TenantYqxhjdJobDa().getTableName(), renwuid, "FUSHEN_PERSON");
            if (nofpcs > 0) {

            } else {
                TenantYqxhjdJob yqxhjdJob1 = new TenantYqxhjdJob();
                yqxhjdJob1.setId(renwuid);
                yqxhjdJob1.setJiandingstate(5);
                destructionMapper.updatejobinfo(yqxhjdJob1);
                TenantYqxhjdTask task1 = new TenantYqxhjdTask();
                task1.setStatus(4);
                task1.setRenwuid(renwuid);
                task1.setCaozuoren(String.valueOf(user.getUserId()));
                task1.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                destructionMapper.updatetask(task1);
                TenantYqxhjdTask task2 = new TenantYqxhjdTask();
                task2.setStatus(5);
                task2.setRenwuid(renwuid);
                task2.setCaozuoren(String.valueOf(user.getUserId()));
                task2.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                destructionMapper.updatetask(task2);
                TenantYqxhjdTask task3 = new TenantYqxhjdTask();
                task3.setStatus(2);
                task3.setRenwuid(renwuid);
                task3.setCaozuoren(String.valueOf(user.getUserId()));
                task3.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                destructionMapper.updatetask(task3);
            }
        } else {
            int nofpcs = -1;
            if ("fushen".equals(type)) {
                nofpcs = isOpenIdentifyMapper.getnofpcsnum(new TenantYqxhjdJobDa().getTableName(), renwuid, "FUSHEN_PERSON");
                if (nofpcs == 0) {
                    TenantYqxhjdTask task3 = new TenantYqxhjdTask();
                    task3.setStatus(2);
                    task3.setRenwuid(renwuid);
                    task3.setCaozuoren(String.valueOf(user.getUserId()));
                    task3.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                    destructionMapper.updatetask(task3);
                }
            }

        }
        return 1;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int refp(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        String statefield = "chushen".equals(type) ? "CHUSHEN_STATE" : "FUSHEN_STATE";
        String personfield = "chushen".equals(type) ? "CHUSHEN_PERSON" : "FUSHEN_PERSON";
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        int state = (int) getjobinfo.get("JIANDINGSTATE");
        if ("chushen".equals(type)) {
            if (state > 2) {
                throw new RuntimeException("已在流程中,无法调整初审任务分配");
            }
        } else {
            if (state > 4) {
                throw new RuntimeException("已在流程中,无法调整复审任务分配");
            }
        }
        TenantYqxhjdTask task3 = new TenantYqxhjdTask();
        task3.setStatus(2);
        task3.setRenwuid(renwuid);
        task3.setCaozuoren(String.valueOf(user.getUserId()));
        task3.setEndtime(null);
        destructionMapper.updatetask(task3);
        return isOpenIdentifyMapper.refp(new TenantYqxhjdJobDa().getTableName(), statefield, personfield, renwuid);
    }

    @Override
    public int tzry(JSONObject json) {
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        Long olduser = json.getLong("olduser");
        Long newuser = json.getLong("newuser");
        String personfield = "chushen".equals(type) ? "CHUSHEN_PERSON" : "FUSHEN_PERSON";
        String jobpersonfield = "chushen".equals(type) ? "CHUSHENPEOPLE" : "FUSHENPEOPLE";
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        int state = (int) getjobinfo.get("JIANDINGSTATE");
        //任务单状态是否已经过了节点
        if ("chushen".equals(type)) {
            if (state > 2) {
                throw new RuntimeException("初审任务分配结束,无法调整初审人员");
            }
        } else {
            if (state > 4) {
                throw new RuntimeException("复审任务分配结束,无法调整复审人员");
            }
        }
        //判断被调整的人是不是已经被分配了任务
        int hasnum = isOpenIdentifyMapper.gethasjobbyuser(olduser, renwuid, new TenantYqxhjdJobDa().getTableName(), personfield);
        if (hasnum > 0) {
            throw new RuntimeException("当前人员已被分配" + ("chushen".equals(type) ? "初审" : "复审") + "任务,请先重新分配" + ("chushen".equals(type) ? "初审" : "复审") + "!");
        }
        List<String> userlist = Arrays.asList(String.valueOf(getjobinfo.get(jobpersonfield)).split(","));
        for (int i = 0; i < userlist.size(); i++) {
            if (olduser == Long.parseLong(userlist.get(i))) {
                userlist.set(i, String.valueOf(newuser));
                break;
            }
        }
        Set peopleset = new HashSet(userlist);
        if (peopleset.size() != userlist.size()) {
            throw new RuntimeException("所选人员已存在!请重新选择");
        }
        return isOpenIdentifyMapper.tzry(YqxhjdJob.getTableName(), renwuid, jobpersonfield, userlist.toString().replace("[", "").replace("]", "").replace(" ", ""));

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int fqjd(Long renwuid) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob tenantYqxhjdJob = new TenantYqxhjdJob();
        tenantYqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(tenantYqxhjdJob);
        if (!String.valueOf(user.getUserId()).equals(String.valueOf(getjobinfo.get("CREATOR")))) {
            throw new RuntimeException("只有创建人才可以发起鉴定!");
        }
        //状态判断
        if (!"2".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            throw new RuntimeException("只有处于分配中状态的任务才能发起鉴定！");
        }
        //判断是否分配了初审任务
        int nofpcs = isOpenIdentifyMapper.getnofpcsnum(new TenantYqxhjdJobDa().getTableName(), renwuid, "CHUSHEN_PERSON");
        if (nofpcs > 0) {
            throw new RuntimeException("此任务中还有未分配初审人的档案，请先进行分配!");
        }

        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        yqxhjdJob.setJiandingstate(3);
        destructionMapper.updatejobinfo(yqxhjdJob);
        TenantYqxhjdTask task = new TenantYqxhjdTask();
        task.setRenwuid(renwuid);
        task.setStatus(3);
        task.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        destructionMapper.updatetask(task);
        return 1;
    }

    @Override
    public List<Map<String, Object>> followd(Long renwuid) {
        return isOpenIdentifyMapper.gettaskinfo(renwuid, new TenantYqxhjdTask().getTableName(), new TenantSysDictData().getTableName());
    }

    @Override
    public List<Map<String, Object>> getchushenjob() {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        List<Map<String, Object>> chushenlist = isOpenIdentifyMapper.getchushenjob(new TenantYqxhjdJobDa().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantCategory().getTableName(), user.getUserId());
        return chushenlist;
    }

    @Override
    public Map<String, Object> getchushennum(Long renwuid, Long userId) {
        return isOpenIdentifyMapper.getchushennum(renwuid, new TenantYqxhjdJobDa().getTableName(), userId);
    }

    @Override
    public List<Map<String, Object>> cssplist(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String jdstate = json.getString("jdstate");
        String fields = json.getString("fields");//需要查询的字段
        fields = "b.id,b." + fields.replace(",", ",b.");
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" b.MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        if (null != jdstate && !"".equals(jdstate)) {
            sb.append(" a.CHUSHEN_STATE =" + jdstate + " ");
        } else {
            sb.append(" 1=1 ");
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            int type = -1;
            String tablefield = "";
            String sub = getjobinfo.get("SUB_TABLE_NAME").toString();
            sub = sub.substring(sub.length() - 3, sub.length() - 2);
            if ("F".equalsIgnoreCase(sub)) {//档案层
                type = 0;
                tablefield = "FILE_TABLE_NAME";
            } else if ("V".equalsIgnoreCase(sub)) {//案卷层
                type = 1;
                tablefield = "FOLDER_TABLE_NAME";
            } else if ("X".equalsIgnoreCase(sub)) {//项目层
                type = 1;
                tablefield = "FOLDER_TABLE_NAME";
            } else if ("E".equalsIgnoreCase(sub)) {//电子文件层
                type = 2;
                tablefield = "EFILE_TABLE_NAME";
            }
            String subtablename = getjobinfo.get("SUB_TABLE_NAME").toString();
            String subsub = subtablename.substring(subtablename.length() - 3, subtablename.length() - 2);
            if ("X".equalsIgnoreCase(subsub)) {
                subtablename = subtablename.substring(0, subtablename.length() - 3) + "V" + subtablename.substring(subtablename.length() - 2);
            }
            Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), subtablename, tablefield);
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(cateinfo.get("ID"))), menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        String subtablename = getjobinfo.get("SUB_TABLE_NAME").toString();
        String subsub = subtablename.substring(subtablename.length() - 3, subtablename.length() - 2);
        if ("X".equalsIgnoreCase(subsub)) {
            subtablename = subtablename.substring(0, subtablename.length() - 3) + "V" + subtablename.substring(subtablename.length() - 2);
        }
        startPage();
        return isOpenIdentifyMapper.cssplist(new TenantYqxhjdJobDa().getTableName(), subtablename, renwuid, user.getUserId(), sb.toString(), orderstr, jdstate, fields);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String chushentijiao(JSONObject json) {
        String type = json.getString("type");//初审/复审
        Long renwuid = json.getLong("renwuid");
        List daids = json.getJSONArray("daids");
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        String jiandingfield = "";
        String tijiaofield = "";
        int state = -1;
        int jobstatechangeto = -1;
        if ("chushen".equals(type)) {
            jiandingfield = "CHUSHEN_JIANDING";
            tijiaofield = "CHUSHEN_TIJIAO";
            state = 3;
            jobstatechangeto = 5;
        } else {
            jiandingfield = "FUSHEN_JIANDING";
            tijiaofield = "FUSHEN_TIJIAO";
            state = 5;
            jobstatechangeto = 6;
        }
        TenantYqxhjdJob tenantYqxhjdJob1 = new TenantYqxhjdJob();
        tenantYqxhjdJob1.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(tenantYqxhjdJob1);
        //状态判断
        if ("9".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            throw new RuntimeException("任务已撤销！");
        }
        //判断是否都初审/复审过
        int i = isOpenIdentifyMapper.getspnum(new TenantYqxhjdJobDa().getTableName(), renwuid, jiandingfield, daids);
        if (i > 0) {
            return "所选数据中存在未进行" + ("chushen".equals(type) ? "初审" : "复审") + "的数据,请先进行审批!";
        }
        //修改提交字段
        isOpenIdentifyMapper.chushentijiao(new TenantYqxhjdJobDa().getTableName(), renwuid, tijiaofield, daids);
        //修改流程表中操作人
        isOpenIdentifyMapper.updatetaskcaozuoren(new TenantYqxhjdTask().getTableName(), renwuid, state, user.getUserId());
        //判断此单中档案是否都已经提交
        int j = isOpenIdentifyMapper.gettijiaonum(new TenantYqxhjdJobDa().getTableName(), renwuid, tijiaofield);
        if (j > 0) {//还有未提交的,不需要操作

        } else {//都提交了
            //如果此单中任务都被提交,提交后,进入下一环节
            TenantYqxhjdJob tenantYqxhjdJob = new TenantYqxhjdJob();
            tenantYqxhjdJob.setId(renwuid);
            //如果是初审完成,复审人可能并未分配,任务将进入待复审状态
            if ("chushen".equals(type)) {
                int k = isOpenIdentifyMapper.getnofushenpersonnum(new TenantYqxhjdJobDa().getTableName(), renwuid);
                if (k > 0) {
                    jobstatechangeto = 4;
                }
            }
            tenantYqxhjdJob.setJiandingstate(jobstatechangeto);
            destructionMapper.updatejobinfo(tenantYqxhjdJob);
            //如果此单中任务都被提交,修改结束时间
            TenantYqxhjdTask yqxhjdTask = new TenantYqxhjdTask();
            yqxhjdTask.setRenwuid(renwuid);
            yqxhjdTask.setStatus(state);
            yqxhjdTask.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
            destructionMapper.updatetask(yqxhjdTask);
            if (jobstatechangeto != 4) {
                TenantYqxhjdTask yqKfjdTask1 = new TenantYqxhjdTask();
                yqKfjdTask1.setRenwuid(renwuid);
                yqKfjdTask1.setStatus(jobstatechangeto);
                yqKfjdTask1.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                destructionMapper.updatetask(yqKfjdTask1);
            } else {
                TenantYqxhjdTask yqKfjdTask1 = new TenantYqxhjdTask();
                yqKfjdTask1.setRenwuid(renwuid);
                yqKfjdTask1.setStatus(4);
                yqKfjdTask1.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
                destructionMapper.updatetask(yqKfjdTask1);
            }

        }
        return "提交成功";
    }

    @Override
    public String updateshending(JSONObject json) {
        String level = json.getString("level");
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        Long daid = json.getLong("daid");
        String jdvalue = json.getString("jdvalue");
        String jiandingfield = "";
        String jiandingstate = "";
        if ("chushen".equals(type)) {
            jiandingfield = "CHUSHEN_JIANDING";
            jiandingstate = "CHUSHEN_STATE";
        } else {
            jiandingfield = "FUSHEN_JIANDING";
            jiandingstate = "FUSHEN_STATE";
        }

        String tableName = "";
        if ("v_f".equals(level)) {//卷内件
            tableName = new TenantYqxhjdFolderDa().getTableName();
        } else {//说明是最外层 可能是f v x
            tableName = new TenantYqxhjdJobDa().getTableName();
            if ("f".equals(level)) {//件直接审
            } else if ("v".equals(level)) {//案卷判断卷内件
                Integer allnum = destructionMapper.getvfxhnum(new TenantYqxhjdFolderDa().getTableName(), renwuid, daid);
                //案卷需要判断卷内件是否已经鉴定
                int i = isOpenIdentifyMapper.getjiandingnum(new TenantYqxhjdFolderDa().getTableName(), renwuid, daid, jiandingstate);
                if (i > 0) {
                    return "此案卷中存在未经" + ("chushen".equals(type) ? "初审" : "复审") + "过的档案!";
                }
                if ("0".equals(jdvalue)) {//不销毁
                    //案卷不销毁,卷内件销毁 ,可以
                } else if ("1".equals(jdvalue)) {//销毁
                    //判断卷内件是否都销毁
                    Integer noxh = destructionMapper.getxhnxhnum(new TenantYqxhjdFolderDa().getTableName(), renwuid, jiandingfield, "1", daid);
                    if (allnum != noxh) {
                        return "案卷销毁时,卷内件必须全都销毁,请重新选择!";
                    }
                }

            }
        }
        isOpenIdentifyMapper.updateshending(tableName, renwuid, daid, jiandingfield, jiandingstate, jdvalue);
        return "成功!";
    }

    @Override
    public Integer updatebeizhu(JSONObject json) {
        String level = json.getString("level");
        String type = json.getString("type");
        Long renwuid = json.getLong("renwuid");
        Long daid = json.getLong("daid");
        String beizhu = json.getString("beizhu");
        String tableName = "";
        String liyoufield = "";
        if ("v_f".equals(level)) {
            tableName = new TenantYqxhjdFolderDa().getTableName();
        } else {
            tableName = new TenantYqxhjdJobDa().getTableName();
        }
        if ("chushen".equals(type)) {
            liyoufield = "CHUSHEN_BEIZHU";
        } else {
            liyoufield = "FUSHEN_BEIZHU";
        }
        return isOpenIdentifyMapper.updateliyou(tableName, liyoufield, beizhu, renwuid, daid);
    }

    @Override
    public List<Map<String, Object>> getdetaillist(JSONObject json) {
        String level = json.getString("level");
        Long daid = json.getLong("daid");
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String fields = json.getString("fields");//需要查询的字段
        fields = "b.id,b." + fields.replace(",", ",b.");
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" b.MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        sb.append(" 1=1 ");
        String tableName = "";
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        String type = getjobinfo.get("SUB_TABLE_NAME").toString().substring(getjobinfo.get("SUB_TABLE_NAME").toString().length() - 3, getjobinfo.get("SUB_TABLE_NAME").toString().length() - 2);
        int applytype = -1;
        if ("V".equalsIgnoreCase(type)) {
            type = "FOLDER_TABLE_NAME";
            applytype = 1;
        } else if ("F".equalsIgnoreCase(type)) {
            type = "FILE_TABLE_NAME";
            applytype = 0;
        } else {
            type = "ITEM_TABLE_NAME";
            applytype = 3;
        }
        Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), (String) getjobinfo.get("SUB_TABLE_NAME"), type);

        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(cateinfo.get("ID"))), menuId, applytype);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        if ("v".equals(level)) {//查看卷内件
            return isOpenIdentifyMapper.getdetaillist((String) cateinfo.get("FILE_TABLE_NAME"), new TenantYqxhjdFolderDa().getTableName(), daid, renwuid, fields, sb.toString(), orderstr, new TenantYqxhjdJobDa().getTableName());
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> getfushenjob() {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        List<Map<String, Object>> chushenlist = isOpenIdentifyMapper.getfushenjob(new TenantYqxhjdJobDa().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantCategory().getTableName(), user.getUserId());
        return chushenlist;
    }

    @Override
    public Map<String, Object> getfushennum(Long renwuid, Long userid) {
        return isOpenIdentifyMapper.getfushennum(renwuid, new TenantYqxhjdJobDa().getTableName(), userid);
    }

    @Override
    public List<Map<String, Object>> fssplist(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String jdstate = json.getString("jdstate");//鉴定状态
        String chushenresult = json.getString("chushenresult");//初审结果
        String fields = json.getString("fields");//需要查询的字段
        fields = "b." + fields.replace(",", ",b.");
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" b.MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        if (null != jdstate && !"".equals(jdstate)) {
            sb.append(" a.FUSHEN_STATE =" + jdstate + " ");
        } else {
            sb.append(" 1=1 ");
        }
        if (null != chushenresult && !"".equals(chushenresult)) {
            sb.append(" and a.CHUSHEN_JIANDING =" + chushenresult + " ");
        } else {
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            int type = -1;
            String tablefield = "";
            String sub = getjobinfo.get("SUB_TABLE_NAME").toString();
            sub = sub.substring(sub.length() - 3, sub.length() - 2);
            if ("F".equalsIgnoreCase(sub)) {//档案层
                type = 0;
                tablefield = "FILE_TABLE_NAME";
            } else if ("V".equalsIgnoreCase(sub)) {//案卷层
                type = 1;
                tablefield = "FOLDER_TABLE_NAME";
            } else if ("X".equalsIgnoreCase(sub)) {//项目层
                type = 1;
                tablefield = "ITEM_TABLE_NAME";
            } else if ("E".equalsIgnoreCase(sub)) {//电子文件层
                type = 2;
                tablefield = "EFILE_TABLE_NAME";
            }
            Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), (String) getjobinfo.get("SUB_TABLE_NAME"), tablefield);
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(cateinfo.get("ID"))), menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        String subtablename = getjobinfo.get("SUB_TABLE_NAME").toString();
        String sub = subtablename.substring(subtablename.length() - 3, subtablename.length() - 2);
        if ("X".equalsIgnoreCase(sub)) {
            subtablename = subtablename.substring(0, subtablename.length() - 3) + "V" + subtablename.substring(subtablename.length() - 2);
        }
        startPage();
        return isOpenIdentifyMapper.fssplist(new TenantYqxhjdJobDa().getTableName(), subtablename, renwuid, user.getUserId(), sb.toString(), orderstr, jdstate, fields);

    }

    @Override
    public int choucha(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        Long daid = json.getLong("daid");
        String type = json.getString("type");
        String tableName = "";
        if ("f".equals(type) || "v".equals(type)) {
            tableName = new TenantYqxhjdJobDa().getTableName();
        } else if ("v_f".equals(type)) {
            tableName = new TenantYqxhjdFolderDa().getTableName();
        }
        return isOpenIdentifyMapper.choucha(tableName, renwuid, daid);
    }

    @Override
    public List<Map<String, Object>> getsdjoblist() {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        List<Map<String, Object>> chushenlist = isOpenIdentifyMapper.getsdjoblist(new TenantYqxhjdJobDa().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantCategory().getTableName(), user.getUserId());
        return chushenlist;
    }

    @Override
    public List<Map<String, Object>> sdlist(JSONObject json) {
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String chushenresult = json.getString("chushenresult");//鉴定状态
        String fushenresult = json.getString("fushenresult");//初审结果
        String fields = json.getString("fields");//需要查询的字段
        fields = "b.id,b." + fields.replace(",", ",b.");
        JSONArray jsonArray = json.getJSONArray("searchcolumn");//查询条件
        StringBuilder sb = new StringBuilder(" and ");//用于拼接条件
        String orderstr = json.getString("order");//用于排序
        if (null == jsonArray) {
            jsonArray = new JSONArray();
        }
        if(FBswitch){
            List<TenantRyMjDzb> getdamjbyrymj = mijiComparisonTableService.getdamjbyrymj();
            sb.append(" b.MJ in ('" + getdamjbyrymj.stream().map(m->m.getDaMj()).collect(Collectors.joining("','")) +"') and ");
        }
        if (jsonArray.size() > 0) {
            wenjianzhengliService.concatQueryCondition(jsonArray, sb);
        }
        if (null != fushenresult && !"".equals(fushenresult)) {
            sb.append(" a.FUSHEN_JIANDING =" + fushenresult + " ");
        } else {
            sb.append(" 1=1 ");
        }
        if (null != chushenresult && !"".equals(chushenresult)) {
            sb.append(" and a.CHUSHEN_JIANDING =" + chushenresult + " ");
        } else {
        }
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(yqxhjdJob);
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {
            int type = -1;
            String tablefield = "";
            String sub = getjobinfo.get("SUB_TABLE_NAME").toString();
            sub = sub.substring(sub.length() - 3, sub.length() - 2);
            if ("F".equalsIgnoreCase(sub)) {//档案层
                type = 0;
                tablefield = "FILE_TABLE_NAME";
            } else if ("V".equalsIgnoreCase(sub)) {//案卷层
                type = 1;
                tablefield = "FOLDER_TABLE_NAME";
            } else if ("X".equalsIgnoreCase(sub)) {//项目层
                type = 3;
                tablefield = "ITEM_TABLE_NAME";
            } else if ("E".equalsIgnoreCase(sub)) {//电子文件层
                type = 1;
                tablefield = "EFILE_TABLE_NAME";
            }
            Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), (String) getjobinfo.get("SUB_TABLE_NAME"), tablefield);
            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(cateinfo.get("ID"))), menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        String subtablename = getjobinfo.get("SUB_TABLE_NAME").toString();
        String sub = subtablename.substring(subtablename.length() - 3, subtablename.length() - 2);
        if ("X".equalsIgnoreCase(sub)) {
            subtablename = subtablename.substring(0, subtablename.length() - 3) + "V" + subtablename.substring(subtablename.length() - 2);
        }
        startPage();
        return isOpenIdentifyMapper.sdlist(new TenantYqxhjdJobDa().getTableName(), subtablename, renwuid, user.getUserId(), sb.toString(), orderstr, fields, yqxhjdJob.getTableName());

    }

    @Override
    public int changesdresult(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        Long daid = json.getLong("daid");
        String bgqx = json.getString("shendingresult");
        Map map = isOpenIdentifyMapper.getdainfo(new TenantYqxhjdJobDa().getTableName(), renwuid, daid);
        if (null == map.get("SHENDING_STATE") || "".equals(map.get("SHENDING_STATE"))) {//根据复审结果
            String fushenresult = String.valueOf(map.get("FUSHEN_JIANDING"));
            TenantYqxhjdJobDa jobDa = new TenantYqxhjdJobDa();
            jobDa.setShendingState(bgqx);
            jobDa.setRenwuid(renwuid);
            jobDa.setDaid(daid);
            destructionMapper.updatedatable1(jobDa);
            if ("v".equals(map.get("TYPE"))) {//修改卷内件
                TenantYqxhjdFolderDa folderDa = new TenantYqxhjdFolderDa();
                folderDa.setShendingState(bgqx);
                folderDa.setRenwuid(renwuid);
                folderDa.setVid(daid);
                destructionMapper.updatefolderda1(folderDa);
            }
        } else {//已经改过
            String fushenresult = String.valueOf(map.get("SHENDING_STATE"));
            TenantYqxhjdJobDa jobDa = new TenantYqxhjdJobDa();
            jobDa.setShendingState(bgqx);
            jobDa.setRenwuid(renwuid);
            jobDa.setDaid(daid);
            destructionMapper.updatedatable1(jobDa);
            if ("v".equals(map.get("TYPE"))) {//修改卷内件
                TenantYqxhjdFolderDa folderDa = new TenantYqxhjdFolderDa();
                folderDa.setShendingState(bgqx);
                folderDa.setRenwuid(renwuid);
                folderDa.setVid(daid);
                destructionMapper.updatefolderda1(folderDa);
            }
        }
        return 1;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int shendingtijiao(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        //List ids=json.getJSONArray("ids");
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        TenantYqxhjdJob tenantYqxhjdJob = new TenantYqxhjdJob();
        tenantYqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(tenantYqxhjdJob);
        //状态判断
        if ("9".equals(String.valueOf(getjobinfo.get("JIANDINGSTATE")))) {
            throw new RuntimeException("任务已撤销！");
        }
        //更新任务流程表
        TenantYqxhjdTask task = new TenantYqxhjdTask();
        task.setRenwuid(renwuid);
        task.setCaozuoren(String.valueOf(user.getUserId()));
        task.setStatus(6);
        task.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        destructionMapper.updatetask(task);
        TenantYqxhjdTask task1 = new TenantYqxhjdTask();
        task1.setRenwuid(renwuid);
        task1.setCaozuoren(String.valueOf(user.getUserId()));
        task1.setStatus(7);
        task1.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        task1.setEndtime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        destructionMapper.updatetask(task1);
        /*TenantYqxhjdTask task2 = new TenantYqxhjdTask();
        task2.setRenwuid(renwuid);
        task2.setStatus(8);
        task2.setStarttime(DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss"));
        destructionMapper.updatetask(task2);*/
        //更新数据表
        TenantYqxhjdJobDa yqxhjdJobDa = new TenantYqxhjdJobDa();
        yqxhjdJobDa.setRenwuid(renwuid);
        destructionMapper.shendingtijiao(yqxhjdJobDa);
        //更新卷内件表
        TenantYqxhjdFolderDa folderDa = new TenantYqxhjdFolderDa();
        folderDa.setRenwuid(renwuid);
        destructionMapper.shendingtijiaofolderda(folderDa);
        //更新任务表
        TenantYqxhjdJob yqxhjdJob = new TenantYqxhjdJob();
        yqxhjdJob.setId(renwuid);
        yqxhjdJob.setJiandingstate(7);
        yqxhjdJob.setShendingResult(1);
        destructionMapper.updatejobinfo(yqxhjdJob);
        return 1;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int jiandingshengxiao(JSONObject json) {
        List jobids = json.getJSONArray("jobids");
        //判断是不是审定完成状态,判断是不是当前人提交的任务
        LoginUser user = SecurityUtils.getLoginUser();
        if (user == null) {
            user = new LoginUser();
            user.setUserId(1L);
        }
        List<Map<String, Object>> maps = isOpenIdentifyMapper.getstateanduser(new TenantYqxhjdJob().getTableName(), jobids);
        for (int i = 0; i < maps.size(); i++) {
            String state = String.valueOf(maps.get(i).get("JIANDINGSTATE"));
            String userid = String.valueOf(maps.get(i).get("CREATOR"));
            if("8".equals(state)){
                continue;
            }
            if ("9".equals(state)) {
                throw new RuntimeException("所选任务中存在已经撤销的任务,请重新选择!");
            }
            if (!"7".equals(state)) {
                throw new RuntimeException("所选任务中存在非审定完成状态的任务,请重新选择!");
            }
            /*if (!userid.equals(String.valueOf(user.getUserId()))) {
                throw new RuntimeException("所选任务中存在非当前用户创建的任务,请重新选择!");
            }*/
            String subTableName = (String) maps.get(i).get("SUB_TABLE_NAME");
            String type = subTableName.substring(subTableName.length() - 3, subTableName.length() - 2);
            String tablename = "";
            if ("X".equalsIgnoreCase(type)) {
                tablename = "ITEM_TABLE_NAME";
            } else if ("V".equalsIgnoreCase(type)) {
                tablename = "FOLDER_TABLE_NAME";
            } else {
                tablename = "FILE_TABLE_NAME";
            }

            //获取门类信息
            Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), subTableName, tablename);
            String jobdatable = new TenantYqxhjdJobDa().getTableName();
            String jobvftable = new TenantYqxhjdFolderDa().getTableName();
            String idfsql = "select daid from " + jobdatable + " where renwuid=" + maps.get(i).get("ID") + " and shending_state=1 ";
            String nowdate = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:ss");
            //添加过程信息
            addBehavior(idfsql);
            if ("x".equalsIgnoreCase(type)) {//项目类型
                //处理卷
                destructionMapper.updateresult(new TenantYqFolder().getTableName(), "FOLDER_ID", (String) getcateinfo.get("FOLDER_TABLE_NAME"), "ID", idfsql, jobdatable, String.valueOf(maps.get(i).get("ID")), nowdate);
                //处理件
                String idvfsql = "select daid from " + jobvftable + " where vid in(select daid from " + jobdatable + " where renwuid=" + maps.get(i).get("ID") + ") and shending_state=1";
                //添加过程信息
                addBehavior(idvfsql);
                destructionMapper.updateresult(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idvfsql, jobvftable, String.valueOf(maps.get(i).get("ID")), nowdate);//修改件主表/件分表
            } else if ("v".equalsIgnoreCase(type)) {//组卷类型
                //处理卷
                destructionMapper.updateresult(new TenantYqFolder().getTableName(), "FOLDER_ID", (String) getcateinfo.get("FOLDER_TABLE_NAME"), "ID", idfsql, jobdatable, String.valueOf(maps.get(i).get("ID")), nowdate);
                //处理件
                String idvfsql = "select daid from " + jobvftable + " where vid in(select daid from " + jobdatable + " where renwuid=" + maps.get(i).get("ID") + ") and shending_state=1";
                //添加过程信息
                addBehavior(idvfsql);
                destructionMapper.updateresult(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idvfsql, jobvftable, String.valueOf(maps.get(i).get("ID")), nowdate);//修改件主表/件分表
            } else if ("f".equalsIgnoreCase(type)) {//组件类型
                destructionMapper.updateresult(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idfsql, jobdatable, String.valueOf(maps.get(i).get("ID")), nowdate);//修改件主表/件分表
            }
            TenantYqxhjdJob job = new TenantYqxhjdJob();
            job.setId(Long.parseLong(String.valueOf(maps.get(i).get("ID"))));
            job.setJiandingenddate(nowdate);
            job.setJiandingstate(8);
            destructionMapper.updatejobinfo(job);
            TenantYqxhjdTask task = new TenantYqxhjdTask();
            task.setRenwuid(Long.parseLong(String.valueOf(maps.get(i).get("ID"))));
            task.setStatus(8);
            task.setCaozuoren(String.valueOf(user.getUserId()));
            task.setStarttime(nowdate);
            task.setEndtime(nowdate);
            destructionMapper.updatetask(task);
        }

        return 1;
    }

    @Async
    public void addBehavior(String selectIdSql) {
        List<Map<String, Object>> list = yqdaarticulatedMapper.executeSql(selectIdSql);
        if (list != null && list.size() != 0 && list.get(0) != null) {
            list.stream().forEach(map -> {
                Long daid = Long.valueOf(map.get("DAID").toString());
                BusinessBehaviorUtil.add(daid, BusinessBehavior.XIAOHUI);
            });
        }
    }

    @Override
    public int jiandingagin(JSONObject json) {
        List ids = json.getJSONArray("ids");
        String level = json.getString("level");
        Long renwuid = json.getLong("renwuid");
        TenantYqxhjdJob job = new TenantYqxhjdJob();
        job.setId(renwuid);
        Map<String, Object> map = destructionMapper.getjobinfo(job);
        if (!"8".equals(String.valueOf(map.get("JIANDINGSTATE")))) {
            return 0;
        }
        String subTableName = (String) map.get("SUB_TABLE_NAME");
        String type = subTableName.substring(subTableName.length() - 3, subTableName.length() - 2);
        if ("X".equalsIgnoreCase(type)) {
            type = "ITEM_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(type)) {
            type = "FOLDER_TABLE_NAME";
        } else {
            type = "FILE_TABLE_NAME";
        }
        //获取门类信息
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), subTableName, type);
        String jobdatable = new TenantYqxhjdJobDa().getTableName();
        String jobvftable = new TenantYqxhjdFolderDa().getTableName();
        String idfsql = ids.toString().replace("[", "").replace("]", "").replace(" ", "").replace("\"", "");
        if ("v".equals(level)) {
            //处理卷
            isOpenIdentifyMapper.jiandingagin(new TenantYqFolder().getTableName(), "FOLDER_ID", (String) getcateinfo.get("FOLDER_TABLE_NAME"), "ID", idfsql);
            //处理件
            String idvfsql = "select daid from " + jobvftable + " where vid in(" + idfsql + ")";
            isOpenIdentifyMapper.jiandingagin(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idvfsql);//修改件主表/件分表
        } else if ("f".equals(level)) {
            isOpenIdentifyMapper.jiandingagin(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idfsql);//修改件主表/件分表
        } else if ("v_f".equals(level)) {
            isOpenIdentifyMapper.jiandingagin(new TenantYqda().getTableName(), "DA_ID", (String) getcateinfo.get("FILE_TABLE_NAME"), "ID", idfsql);//修改件主表/件分表
        }
        return 1;
    }

    @Override
    public List<Map<String, Object>> tongji(JSONObject json) {
        String type = json.getString("type");
        if ("jobname".equals(type)) {
            return destructionMapper.gettongjibyjobname(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        } else if ("user".equals(type)) {
            String level = json.getString("level");
            String userid = json.getString("userid");
            if ("chushen".equals(level)) {
                return destructionMapper.gettongjibyuserchushen(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                        , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName(), userid);
            } else {
                return destructionMapper.gettongjibyuserfushen(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                        , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName(), userid);
            }

        } else if ("category".equals(type)) {
            return destructionMapper.gettongjibycate(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        } else if ("qzh".equals(type)) {
            return destructionMapper.gettongjibyqzh(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        }
        return null;
    }

    @Override
    public Map<String, Object> getuser(JSONObject json) {
        String type = json.getString("type");
        Long id = json.getLong("id");
        String field = "";
        if ("chushen".equals(type)) {
            field = "CHUSHENPEOPLE";
        } else {
            field = "FUSHENPEOPLE";
        }
        return isOpenIdentifyMapper.getuser(field, new TenantYqxhjdJob().getTableName());
    }

    @Override
    public List<List<String>> getexportjobth() {
        List<List<String>> list = new ArrayList<List<String>>() {{
            List<String> list1 = new ArrayList<String>() {{
                add("序号");
            }};
            add(list1);
            List<String> list2 = new ArrayList<String>() {{
                add("鉴定任务名称");
            }};
            add(list2);
            List<String> list3 = new ArrayList<String>() {{
                add("任务批次号");
            }};
            add(list3);
            List<String> list4 = new ArrayList<String>() {{
                add("全宗号");
            }};
            add(list4);
            List<String> list5 = new ArrayList<String>() {{
                add("鉴定状态");
            }};
            add(list5);
            List<String> list6 = new ArrayList<String>() {{
                add("鉴定组组长");
            }};
            add(list6);
            List<String> list7 = new ArrayList<String>() {{
                add("初审人员");
            }};
            add(list7);
            List<String> list8 = new ArrayList<String>() {{
                add("复审人员");
            }};
            add(list8);
            List<String> list9 = new ArrayList<String>() {{
                add("审定人员");
            }};
            add(list9);
            List<String> list10 = new ArrayList<String>() {{
                add("鉴定创建日期");
            }};
            add(list10);
            List<String> list11 = new ArrayList<String>() {{
                add("任务结束日期");
            }};
            add(list11);
            List<String> list12 = new ArrayList<String>() {{
                add("备注");
            }};
            add(list12);
        }};

        return list;
    }

    @Override
    public List<List<String>> getexportjobdata(List ids) {
        List<Map<String, Object>> resultList = isOpenIdentifyMapper.kfjdjoblist1(new TenantYqxhjdJob().getTableName(), new TenantSysDictData().getTableName(), ids);
        List<List<String>> result = new ArrayList<>();

        for (Map<String, Object> row : resultList) {
            List<String> rowData = new ArrayList<>();

            for (Object value : row.values()) {
                String b2s = String.valueOf(value);
                if (null == b2s || "".equals(b2s) || "null".equals(b2s)) {
                    b2s = "";
                }
                rowData.add(b2s);
            }

            result.add(rowData);
        }
        return result;
    }

    @Override
    public List<List<String>> exportjobdath(JSONObject json) {
        List<List<String>> list = new ArrayList<List<String>>();
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");
        TenantYqxhjdJob job = new TenantYqxhjdJob();
        job.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(job);
        String subTableName = String.valueOf(getjobinfo.get("SUB_TABLE_NAME"));
        String tablenametype = subTableName.substring(subTableName.length() - 3, subTableName.length() - 2);
        String type = "";
        JSONObject json1 = new JSONObject();
        if ("X".equalsIgnoreCase(tablenametype)) {
            json1.put("level", "juan");
            type = "ITEM_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {
            json1.put("level", "juan");
            type = "FOLDER_TABLE_NAME";
        } else if ("F".equalsIgnoreCase(tablenametype)) {
            json1.put("level", "jian");
            type = "FILE_TABLE_NAME";
        }
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), subTableName, type);
        json1.put("categoryId", getcateinfo.get("ID"));
        json1.put("menuId", menuId);
        List<Map<String, String>> getshowfield = cateMdataListService.getshowfield(json1);
        for (int i = 0; i < getshowfield.size(); i++) {
            List<String> listi = new ArrayList<>();
            listi.add(getshowfield.get(i).get("FIELD_CAPTION"));
            list.add(listi);
        }
        List<String> list1 = new ArrayList() {{
            add("初审人");
        }};
        list.add(list1);
        List<String> list2 = new ArrayList() {{
            add("初审鉴定");
        }};
        list.add(list2);
        List<String> list4 = new ArrayList() {{
            add("初审备注");
        }};
        list.add(list4);
        List<String> list5 = new ArrayList() {{
            add("复审人");
        }};
        list.add(list5);
        List<String> list6 = new ArrayList() {{
            add("复审鉴定");
        }};
        list.add(list6);
        List<String> list8 = new ArrayList() {{
            add("复审备注");
        }};
        list.add(list8);
        List<String> list9 = new ArrayList() {{
            add("鉴定结果");
        }};
        list.add(list9);
        return list;
    }

    @Override
    public List<List<String>> exportjobdadata(JSONObject json) {
        Long renwuid = json.getLong("renwuid");
        Long menuId = json.getLong("menuId");//菜单id
        String orderstr = json.getString("order");//用于排序
        List ids = json.getJSONArray("ids");
        String fields = json.getString("fields");
        TenantYqxhjdJob YqxhjdJob = new TenantYqxhjdJob();
        YqxhjdJob.setId(renwuid);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(YqxhjdJob);
        String searchtable = (String) getjobinfo.get("SUB_TABLE_NAME");
        String tablenametype = searchtable.substring(searchtable.length() - 3, searchtable.length() - 2);
        String subname = "";
        int type = -1;
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            type = 0;
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            type = 1;
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            type = 1;
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
            type = 2;
        }
        Map<String, Object> getcateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), searchtable, subname);
        if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            searchtable = String.valueOf(getcateinfo.get("FOLDER_TABLE_NAME"));
        }
        /**处理排序*/
        if (null != orderstr && !"".equals(orderstr)) {
            orderstr = " order by " + orderstr;
        } else {

            String applyorderstr = tenantMdataListService.getorder(Long.parseLong(String.valueOf(getcateinfo.get("ID"))), menuId, type);
            if (null != applyorderstr && !"".equals(applyorderstr)) {
                orderstr = " order by " + applyorderstr;
            }
        }
        fields = isOpenIdentifyserviceimpl.detaildict(fields, Long.parseLong(String.valueOf(getcateinfo.get("ID"))), new TenantSysDictData().getTableName(), type);
        List<Map<String, Object>> resultList = destructionMapper.exportjobdadata(renwuid, new TenantYqxhjdJobDa().getTableName(), searchtable, fields, orderstr, ids, new TenantSysDictData().getTableName());
        List<List<String>> result = new ArrayList<>();

        for (Map<String, Object> row : resultList) {
            List<String> rowData = new ArrayList<>();

            for (Object value : row.values()) {
                String b2s = String.valueOf(value);
                if (null == b2s || "".equals(b2s) || "null".equals(b2s)) {
                    b2s = "";
                }
                rowData.add(b2s);
            }

            result.add(rowData);
        }
        return result;
    }

    @Override
    public List<List<String>> exporttongjith(JSONObject json) {
        String type = json.getString("type");
        if ("jobname".equals(type)) {
            List<String> strlist = new ArrayList<String>() {{
                add("鉴定任务名");
                add("鉴定开始时间");
                add("鉴定结束时间");
                add("档案门类");
                add("类型");
                add("全宗号");
                add("档案数量");
                add("案卷数量");
                add("总页数");
                add("总电子文件数");
                add("不销毁数量");
                add("销毁数量");
                add("异议数量");
                add("初审完成数量");
                add("复审完成数量");
                add("复审抽查数量");
                add("初审完成率");
                add("复审完成率");
                add("抽查率");
            }};
            List<List<String>> returnlist = getthlist(strlist);
            return returnlist;
        } else if ("category".equals(type)) {
            List<String> strlist = new ArrayList<String>() {{
                add("门类");
                add("类型");
                add("全宗号");
                add("档案数量");
                add("案卷数量");
                add("总电子文件数");
                add("总页数");
                add("已初审数量");
                add("已复审数量");
                add("销毁数量");
                add("不销毁数量");
                add("抽检数量");
                add("异议数量");
                add("初审完成率");
                add("复审完成率");
                add("复审抽查率");
            }};
            List<List<String>> returnlist = getthlist(strlist);
            return returnlist;
        } else if ("qzh".equals(type)) {
            List<String> strlist = new ArrayList<String>() {{
                add("全宗号");
                add("类型");
                add("档案数量");
                add("案卷数量");
                add("总电子文件数");
                add("总页数");
                add("已初审数量");
                add("已复审数量");
                add("销毁数量");
                add("不销毁数量");
                add("抽检数量");
                add("异议数量");
                add("初审完成率");
                add("复审完成率");
                add("复审抽查率");
            }};
            List<List<String>> returnlist = getthlist(strlist);
            return returnlist;
        } else if ("user".equals(type)) {
            String level = json.getString("level");
            String userid = json.getString("userid");
            if ("chushen".equals(level)) {
                List<String> strlist = new ArrayList<String>() {{
                    add("初审人");
                    add("鉴定任务名称");
                    add("鉴定开始时间");
                    add("鉴定结束时间");
                    add("门类");
                    add("类型");
                    add("全宗号");
                    add("档案数量");
                    add("案卷数量");
                    add("总电子文件数");
                    add("总页数");
                    add("初审文件数量");
                    add("销毁数量");
                    add("不销毁数量");
                    add("初审完成率");
                }};
                List<List<String>> returnlist = getthlist(strlist);
                return returnlist;
            } else {
                List<String> strlist = new ArrayList<String>() {{
                    add("复审人");
                    add("鉴定任务名称");
                    add("鉴定开始时间");
                    add("鉴定结束时间");
                    add("门类");
                    add("类型");
                    add("全宗号");
                    add("档案数量");
                    add("案卷数量");
                    add("总电子文件数");
                    add("总页数");
                    add("复审文件数量");
                    add("销毁数量");
                    add("不销毁数量");
                    add("抽检数量");
                    add("复审抽检率");
                    add("复审完成率");
                }};
                List<List<String>> returnlist = getthlist(strlist);
                return returnlist;
            }

        }
        return null;
    }

    @Override
    public List<List<String>> exporttongjidata(JSONObject json) {
        String type = json.getString("type");
        List<Map<String, Object>> resultList = new ArrayList<>();
        if ("jobname".equals(type)) {
            resultList = destructionMapper.gettongjibyjobname(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        } else if ("category".equals(type)) {
            resultList = destructionMapper.gettongjibycate(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        } else if ("qzh".equals(type)) {
            resultList = destructionMapper.gettongjibyqzh(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                    , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName());
        } else if ("user".equals(type)) {
            String level = json.getString("level");
            String userid = json.getString("userid");
            if ("chushen".equals(level)) {
                resultList = destructionMapper.gettongjibyuserchushen(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                        , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName(), userid);
            } else {
                resultList = destructionMapper.gettongjibyuserfushen(new TenantYqda().getTableName(), new TenantYqxhjdJob().getTableName(), new TenantYqxhjdJobDa().getTableName()
                        , new TenantYqxhjdFolderDa().getTableName(), new TenantCategory().getTableName(), userid);
            }

        }
        List<List<String>> result = new ArrayList<>();

        for (Map<String, Object> row : resultList) {
            List<String> rowData = new ArrayList<>();
            /*if(Integer.parseInt(String.valueOf(row.get("TYPE"))) == 1){
                row.put("TYPE","卷");
            }else if(Integer.parseInt(String.valueOf(row.get("TYPE"))) == 0){
                row.put("TYPE","件");
            }else if(Integer.parseInt(String.valueOf(row.get("TYPE"))) == 3){
                row.put("TYPE","项目");
            }*/
            for (Object value : row.values()) {
                String b2s = String.valueOf(value);
                if (null == b2s || "".equals(b2s) || "null".equals(b2s)) {
                    b2s = "";
                }
                rowData.add(b2s);
            }

            result.add(rowData);
        }
        return result;
    }

    @Override
    public List<Map<String, Object>> getcomplatejob() {
        return destructionMapper.getcomplatejob(new TenantYqxhjdJob().getTableName());
    }

    @Override
    public List<Map<String, Object>> getqingce(Long id) {
        TenantYqxhjdJob job = new TenantYqxhjdJob();
        job.setId(id);
        Map<String, Object> getjobinfo = destructionMapper.getjobinfo(job);
        String subtablename = (String) getjobinfo.get("SUB_TABLE_NAME");
        String tablenametype = subtablename.substring(subtablename.length() - 3, subtablename.length() - 2);
        String subname = "";
        if ("F".equalsIgnoreCase(tablenametype)) {//档案层
            subname = "FILE_TABLE_NAME";
        } else if ("V".equalsIgnoreCase(tablenametype)) {//案卷层
            subname = "FOLDER_TABLE_NAME";
        } else if ("X".equalsIgnoreCase(tablenametype)) {//项目层
            subname = "ITEM_TABLE_NAME";
        } else if ("E".equalsIgnoreCase(tablenametype)) {//电子文件层
        }
        Map<String, Object> cateinfo = isOpenIdentifyMapper.getcateinfo(new TenantCategory().getTableName(), subtablename, subname);
        return destructionMapper.getqingce((String) getjobinfo.get("SUB_TABLE_NAME"), new TenantYqxhjdJobDa().getTableName(), new TenantCategory().getTableName(), new TenantYqxhjdFolderDa().getTableName(), (String) cateinfo.get("FILE_TABLE_NAME"), id);
    }

    @Override
    public Map<String, Object> getuserbyrenwuid(JSONObject json) {
        String type = json.getString("type");
        String field = "";
        if ("chushen".equals(type)) {
            field = "CHUSHENPEOPLE";
        } else {
            field = "FUSHENPEOPLE";
        }
        Long renwuid = json.getLong("id");
        return isOpenIdentifyMapper.getuserbyrenwuid(field, new TenantYqxhjdJob().getTableName(), renwuid);
    }

    @Override
    public String editcate(Long renwuid) {
        int i = isOpenIdentifyMapper.editcate(new TenantYqxhjdJobDa().getTableName(), renwuid);
        if (i > 0) {
            return "not allow";
        } else {
            return "allow";
        }
    }

    private List<List<String>> getthlist(List<String> strlist) {
        List<List<String>> returnlist = new ArrayList<>();
        for (int i = 0; i < strlist.size(); i++) {
            List<String> listi = new ArrayList<>();
            listi.add(strlist.get(i));
            returnlist.add(listi);
        }
        return returnlist;
    }
}
